﻿using Furion.DatabaseAccessor;
using LimaLims.Core.Entity.System;
using LimaLims.Core.Entity.TestCenter;
using LimaLims.Core.Enum;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.ComponentModel.DataAnnotations;


namespace LimaLims.Core.Entity.Basic
{
    /// <summary>
    /// 班组管理
    /// </summary>
    [Comment("班组管理")]
    public class Team : DEntityTenant, IEntityTypeBuilder<Team>, IEntitySeedData<Team>
    {
        /// <summary>
        /// 车间名称
        /// </summary>
        [Comment("车间名称")]
        [Required, MaxLength(20)]
        public string WorkName { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [Comment("名称")]
        [Required, MaxLength(20)]
        public string Name { get; set; }

        /// <summary>
        /// 所属试验站
        /// </summary>
        [Comment("所属试验站")]
        public long? ExperimentStationId { get; set; }

        public ExperimentStation ExperimentStation { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [Comment("备注"), MaxLength(100)]
        public string Remark { get; set; }

        /// 多对多（用户）
        /// </summary>
        public ICollection<SysUser> SysUsers { get; set; }

        public ICollection<ExperimentPlan> ExperimentPlans { get; set; }

        public void Configure(EntityTypeBuilder<Team> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder
                .HasMany(x => x.SysUsers)
                .WithOne(x => x.Team)
                .HasForeignKey(x => x.TeamId)
                .OnDelete(DeleteBehavior.Restrict); // 必须设置这一行
        }

        public IEnumerable<Team> HasData(DbContext dbContext, Type dbContextLocator)
        {
            return new[]
             {
                new Team
                {
                    Id=242307070910559,TenantId=142307070918780,CreatedTime=DateTime.Now,WorkName="默认车间",Name="默认班组",Remark="系统默认"
                }

            };
        }
    }
}
